﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xyz.BusinessObjects;
using Xyz.DataObjects.Interfaces;

namespace Xyz.DataObjects.Entity.Dao
{
    public class EntityAdministratorDao : IAdministratorDao
    {

        public void CreateAdministrator(Administrator administrator)
        {
            using (var context = EntityObjectFactory.CreateContext())
            {
                AdministratorEntity entity = Mapper.Map(administrator);
                context.AdministratorEntities.AddObject(entity);
                context.SaveChanges();
            }
        }

        public Administrator GetAdministrator(string loginId, string password)
        {
            using (var context = EntityObjectFactory.CreateContext())
            {
                var admin = context.AdministratorEntities.SingleOrDefault(x => x.AdminLoginId == loginId && x.Password == password);

                if (admin != null)
                {
                    return Mapper.Map(admin);
                }
                return null;
            }
        }
    }
}
